package com.example.demo.common;

import com.example.demo.entity.UserInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class UserSessionTools {
    /**
     * 获取当前登录用户
     * @param httpServletRequest
     * @return
     */
    public static UserInfo getLoginUser(HttpServletRequest httpServletRequest){

        HttpSession session = httpServletRequest.getSession(false);
        Object userObj = null;
        if (session!=null&&session.getAttribute(ApplicationVariable.SESSION_KEY_USERINFO)!=null){
            return (UserInfo) session.getAttribute(ApplicationVariable.SESSION_KEY_USERINFO);
        }
        return null;
    }
}
